﻿<?php
require_once("include/header.php");
include_once("maincore.php");
if(!defined("THNOJ")) die ("Outside of the site");
if (!isset($myid)) redirect("index.php");
        require_once("./include/db_info.inc.php");
  $cache_time=2;
        require_once("./include/cache_start.php");
        
require_once("./include/my_func.inc.php");
require_once("./include/db_info.inc.php");
require_once("./include/const.inc.php");

?>


<meta http-equiv='refresh' content='100'>
<title>Kết quả</title>
<div class="body-wrap nobg">
	<div class="wrapper">
		
		
		<div class="main">
			<div class="col-a0">
<center>



<table align='center'>
<tr  class='toprow' align='center'>
<td >ID
<td >Tên
<td >Bài toán
<td >Kết quả
<td >Bộ nhớ
<td >Thời gian
<td >Ngôn ngữ LT
<td >Độ dài
<td >Nộp lúc
<td> Nhận xét
</tr>
<?php 

$sql="select * from solution where ";
$isauthor=false;
if (isset($_GET['p'])) {
	$sql.="problem_id=".$_GET['p'];
	$sql2="select * from problem where problem_id=".$_GET['p']." ";
	$ret=mysql_query($sql2) or die (mysql_error());
	if (mysql_num_rows($ret)) $isauthor=true;
}  else
if (isset($_GET['c'])) {
	$cid=$_GET['c'];
	$sql.="contest_id=".$_GET['c'];
	$sql2="select * from contest where contest_id=".$_GET['c']." ";
	$ret=mysql_query($sql2) or die (mysql_error());
	if (mysql_num_rows($ret)) $isauthor=true;
}
if (!$isauthor) {
	if (strpos($sql," where ")===false) $sql.= " where ";
	$sql.=" user_id='$myid' or problem_id in (select problem_id from problem where author_id='$myid')";
}

$sql.=" order by solution_id desc";
if ($DEBUG) {
	echo "<br>sql3:$sql";
}
if($OJ_MEMCACHE){
	require("./include/memcache.php");
	$result = mysql_query_cache($sql) or die("Error! ".mysql_error());
	$rows_cnt=count($result);
}else{
		
	$result = mysql_query($sql) or die("Error! ".mysql_error());
	$rows_cnt=mysql_num_rows($result);
}
$top=$bottom=-1;
$cnt=0;
if ($start_first){
        $row_start=0;
        $row_add=1;
}else{
        $row_start=$rows_cnt-1;
        $row_add=-1;
}



for ($i=0;$i<$rows_cnt;$i++){
if($OJ_MEMCACHE)
	$row=$result[$i];
else
	$row=mysql_fetch_array($result);
        if ($top==-1) $top=$row['solution_id'];
        $bottom=$row['solution_id'];
        if ($cnt) echo "<tr align=center class='oddrow'>";
        else echo "<tr align=center class='evenrow'>";
        $flag=(!is_running(intval($row['contest_id']))) ||
                        isset($_SESSION['source_browser']) ||
                        isset($_SESSION['administrator']) || 

                        (isset($_SESSION['user_id'])&&!strcmp($row['user_id'],$_SESSION['user_id']));

        $cnt=1-$cnt;
		if ($GV || $ADMIN) 
			echo "<td><a href='admin/runfail.php?s=".$row['solution_id']."'>".$row['solution_id']."</a></td>";
		else
			echo "<td>".$row['solution_id']."</td>";
        echo "<td>".$row['user_id']."";

        if (isset($cid)) 
                echo "<td><a href='problem.php?cid=$cid&pid=".$row['num']."'>".$PID[$row['num']]."</a>";
        else 

                echo "<td><a href='exercise.php?id=".$row['problem_id']."'>".$row['problem_id']."</a>";
        if (intval($row['result'])==11 ){
                echo "<td><a href='ceinfo.php?sid=".$row['solution_id']."' class=".$judge_color[$row['result']].">".$judge_result[$row['result']]."</a>";
        }else if (intval($row['result'])==10 ){
                echo "<td><a href='reinfo.php?sid=".$row['solution_id']."' class=".$judge_color[$row['result']].">".$judge_result[$row['result']]."</a>";

        }else{

                if($OJ_SIM&&$row['sim']&&$row['sim_s_id']!=$row['s_id']) {
                        echo "<td><span class=".$judge_color[$row['result']].">*".$judge_result[$row['result']]."</span>-<span class=red>";
                       
                        if( isset($_SESSION['source_browser'])){

                                        echo "<a href=showsource.php?id=".$row['sim_s_id']." target=original>".$row['sim_s_id']."(".$row['sim']."%)</a>";
                        }else{

                                        echo $row['sim_s_id'];

                        }
                        if(isset($_GET['showsim'])&&isset($row[13])){
                                        echo "$row[13]";
                                
                        }
                        echo     "</span>";
                }else{

                        echo "<td class=".$judge_color[$row['result']].">".($OJ_OI_MODE&&(($row['result']==6)||($row['result']==4))?round($row['pass_rate']*100,0)."%":$judge_result[$row['result']]);
                }
                
        }
        //if (isset($row['pass_rate'])&&$row['pass_rate']>0&&$row['pass_rate']<.98) echo ($row['pass_rate']*100);
		//if (isset($row['pass_rate'])) echo ($row['pass_rate']*100);
        if ($flag){


                if ($row['result']>=4){
                        echo "<td class=red>".$row['memory']." B";
                        echo "<td class=red>".$row['time']." ms";

                }else{
                        echo "<td>------<td>------";
                }

                if (!(isset($_SESSION['user_id'])&&strtolower($row['user_id'])==strtolower($_SESSION['user_id']) || isset($_SESSION['source_browser']))){
                        echo "<td><a target=_blank href=showsource.php?id=".$row['solution_id'].">".$language_name[$row['language']]."</a>/";
                }else{

                        echo "<td><a target=_blank href=showsource.php?id=".$row['solution_id'].">".$language_name[$row['language']]."</a>/";

                        if (isset($cid)) {

                                echo "<a target=_self href=\"submitpage.php?cid=".$cid."&pid=".$row['num']."&sid=".$row['solution_id']."\">Sửa</a>";

                        }else{

                                echo "<a target=_self href=\"submitpage.php?id=".$row['problem_id']."&sid=".$row['solution_id']."\">Sửa</a>";

                        }
                }

                echo "<td>".$row['code_length']." B";
                

        }else echo "<td>------<td>------<td>".$language_name[$row['language']]."<td>------";
        echo "<td>".$row['in_date'];
		echo "<td>NX";
        echo "</tr>\n";
}
mysql_free_result($result);
?>
</table>
<?php echo "[<a href=status.php?".$str2.">Top</a>]&nbsp;&nbsp;";
if (isset($_GET['prevtop']))
        echo "[<a href=status.php?".$str2."&top=".$_GET['prevtop'].">Trang trước</a>]&nbsp;&nbsp;";
else
        echo "[<a href=status.php?".$str2."&top=".($top+20).">Trang trước</a>]&nbsp;&nbsp;";
echo "[<a href=status.php?".$str2."&top=".$bottom."&prevtop=$top>Trang sau</a>]";
?>
</div>
			
			<div class="clear"></div>
		</div>
	</div>
</div>
<?php require_once("include/footer.php");?>
<?php require_once("./include/cache_end.php");?>
